package comValue
{
	import com.esri.ags.Graphic;
	import com.esri.ags.geometry.Extent;
	import com.esri.ags.geometry.Geometry;
	import com.esri.ags.geometry.MapPoint;
	import com.esri.ags.geometry.Polygon;
	import com.esri.ags.geometry.Polyline;
	import com.esri.ags.layers.GraphicsLayer;
	import com.esri.ags.symbols.SimpleLineSymbol;
	
	import flash.external.ExternalInterface;
	
	import mx.controls.Alert;
	import mx.core.UIComponent;
	import mx.managers.PopUpManager;
	
	import widgets.Themes.AllInfoBorderContainer;
	import widgets.WebLinkUrlForm;

	/*
   *该类用于存放一些共有的静态方法，供其他各类使用
	  */


	public class ComMethods
	{
		import adobe.ac.mxeffects.*;
		import com.esri.ags.*;
		import com.esri.ags.geometry.*;
		import com.google.code.flexiframe.IFrame;

		 private static const resultLineSymbol:SimpleLineSymbol=new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,0xFF0000,0.8,2);
		///参数: 需要实现该效果的目标
		///作用:面板之间切换，实现旋转效果
		public static function flipEffect(tagrt:Object):void
		{
			var e:Flip=new Flip(tagrt);
			e.siblings=[tagrt];
			e.direction=DistortionConstants.RIGHT;
			e.duration=500;
			e.play();
		}

		///参数:要素的详细信息对话框,弹出位置
		///作用:通过鼠标点击获取点击要素的详细信息
		public static function showAllInfoWindow(displayObject:UIComponent, pGraphic:Graphic, displayLabel:String="详细信息"):void
		{
			var mainMap:Map=comValue.comValue.mainMap;
		
			var mapPt:MapPoint=getGeomCenter(pGraphic);
			mainMap.infoWindow.label=displayLabel;
			mainMap.infoWindow.closeButtonVisible=true;
			mainMap.infoWindow.content=displayObject;
			mainMap.infoWindow.show(mapPt);

		}

		public static function getGeomCenter(graphic:Graphic):MapPoint
		{
			var pt:MapPoint;
			switch (graphic.geometry&&graphic.geometry.type)
			{
				case Geometry.MULTIPOINT:
				{
					var pts:Multipoint=graphic.geometry as Multipoint;

					if (pts.points.length > 0)
						pt=pts.points[0];
					break;
				}
				case Geometry.MAPPOINT:
				{
					pt=graphic.geometry as MapPoint;
					break;
				}
				case Geometry.POLYLINE:
				{
					const pl:Polyline=graphic.geometry as Polyline;
					const pathCount:Number=pl.paths.length;
					const pathIndex:int=int((pathCount / 2) - 1);
					const midPath:Array=pl.paths[pathIndex];
					const ptCount:Number=midPath.length;
					const ptIndex:int=int((ptCount / 2) - 1);
					pt=pl.getPoint(pathIndex, ptIndex);
					break;
				}
				case Geometry.POLYGON:
				{
					const poly:Polygon=graphic.geometry as Polygon;
					pt=poly.extent.center;
					break;
				}
			}
			return pt;
		}

		/*
		//通过编码获取对应的值桥梁与路段
		//pResultXmlList--传入需要查找的XMllsit
		//s_Field--查找数据字段名
		//s_Key--查找的键值
		//return --返回Value
		*/
		public static function getCodeTransValue(pResultXmlList:XMLList, s_Field:String, s_Key:String):String
		{
			const length:int=pResultXmlList.length();

			for (var i:int=0; i < length; i++)
			{
				if ((pResultXmlList[i].@Field == s_Field) && (pResultXmlList[i].@Key == s_Key))
					return String(pResultXmlList[i].@Value);

			}
			return s_Key;
		}

		/**
		 * 通过js打开查询或统计结果相关网页，该网页隐藏工具栏等不需显示的信息
		 * */
		public static function showResutlWindowFromJS(url:String):void
		{
			ExternalInterface.call('window.open', encodeURI(url), 'result', 'width=1000px,height=650px,resizable=yes,status=no,scrollbars=yes,menubar=no ');
		}

		/**
		 * 显示错误提醒信息
		 * */
		public static function showErrorTips():void
		{
			Alert.show("请重新点击或刷新页面!");
		}
		/**
		 * 添加空间查询要素
		 * */
		public static function addSpatialQueryGraphic(pSelectGraphic:Graphic, graphicsLayer:GraphicsLayer):void
		{
			if (pSelectGraphic)
			{
				var polyLine:Polyline;
				var polygon:Polygon;
				if (pSelectGraphic.geometry.type == Geometry.POLYGON)
				{
					polygon=Polygon(pSelectGraphic.geometry);
					polyLine=new Polyline(polygon.rings);
				}
				else if (pSelectGraphic.geometry.type == Geometry.EXTENT)
				{
					polygon=Extent(pSelectGraphic.geometry).toPolygon();
					polyLine=new Polyline(polygon.rings);
				}
				pSelectGraphic=new Graphic(polyLine,resultLineSymbol);
				 graphicsLayer.add(pSelectGraphic);
			}
		}
	}
}